package org.jgs1904.work.controller;

import java.sql.SQLException;
import java.util.Scanner;

import org.jgs1904.work.entity.Users;
import org.jgs1904.work.service.UserService;

/**
 * 用户控制器
 *
 * @author dyf
 * @date 2020年2月4日
 */
public class UserController {

    private Scanner sc = new Scanner(System.in);
    private UserService userService = new UserService();

    public void login() {

        System.out.println("请输入用户名：");
        String username = sc.next();
        System.out.println("请输入密码：");
        String password = sc.next();

        Users users = null;
        try {
            users = userService.login(Users.builder().username(username).password(password).build());
        } catch (SQLException e) {
            e.printStackTrace();
        }

        if (users == null) {
            System.out.println("登录失败！");
        } else {
            System.out.println("登录成功！");

            MessageController messageController = new MessageController();
            messageController.hello(users);
        }

    }

}
